/*
 * @Descripttion:
 * @version:
 * @Author: mmzhang
 * @Date: 2021-07-27 16:02:34
 * @LastEditTime: 2022-06-14 13:27:05
 */
import dateOpt from '@/biz/option/date.js'
import nameOpt from '@/biz/option/name.js'
import Opt from '@/components/dt/info/Opt.js'
import table from '@/components/dt/table/render.js'

let _this = null

class Column extends Opt {
  constructor(vm) {
    super()
    _this = vm
    this.build()
  }

  build() {
    this.createAll()
    this.opts.push(...this.all)
  }

  createAll() {
    this.all = [
      {
        field: 'privacyNumber',
        minWidth: 120,
        header: {
          filter: {
            title: '隐私号',
            key: 'privacyNumber',

            input: {}
          }
        }
      },
      {
        title: '类型',
        field: 'callType',
        minWidth: 120,
        header: {
          filter: {
            title: '类型',
            key: 'callType',

            select: {
              options: [
                { key: 0, value: '呼出' },
                { key: 1, value: '呼入' },
                { key: 2, value: '个人呼入' }
              ]
            }
          }
        }
      },

      {
        title: '归属地',
        field: 'ascriptionPlace',
        minWidth: 120,
        header: {
          filter: {
            title: '归属地',
            key: 'ascriptionPlace',

            input: {}
          }
        }
      },

      {
        field: 'numberStatus',
        minWidth: 120,
        header: {
          filter: {
            title: '号码状态',
            key: 'status',
            select: {
              options: [
                { key: 'NORMAL', value: '正常' },
                { key: 'ABNORMAL', value: '异常' },
                { key: 'REMOVED', value: '已移除' }
              ]
            }
          }
        }
        // slots: {
        //   default: (params, h) => {
        //     return [h('div', params.row.buildingType == 2 ? '离案' : '在案')]
        //   }
        // }
      },
      {
        field: 'employStatus',
        minWidth: 120,
        header: {
          filter: {
            title: '使用状态',
            key: 'useStatus',
            select: {
              options: [
                { key: '1', value: '闲置中' },
                { key: '2', value: '使用中' },
                { key: '3', value: '保护期' }
              ]
            }
          }
        }
        // slots: {
        //   default: (params, h) => {
        //     return [h('div', params.row.buildingType == 2 ? '离案' : '在案')]
        //   }
        // }
      },
      {
        field: 'businessParty',
        minWidth: 120,
        header: {
          filter: {
            title: '业务方',
            key: 'businessSource',

            select: {
              options: [
                { key: 'LEASE', value: '外呼号租用' },
                { key: 'TOSPUR', value: '案场承接业务' }
              ]
            }
          }
        }
        // slots: {
        //   default: (params, h) => {
        //     return [h('div', params.row.buildingType == 2 ? '离案' : '在案')]
        //   }
        // }
      },

      {
        title: '当前状态持续时间',
        field: 'statusContinueTime',
        minWidth: 180,
        remoteSort: true
      },
      {
        field: 'userName',
        minWidth: 200,
        title: '使用人',
        header: {
          filter: nameOpt.createCounselorPeople({
            key: 'nameOrWorkNo',
            title: '使用人',
            to: (info) => {
              return {
                nameOrWorkNo: info.workNo
              }
            }
          })
        }
      },
      {
        title: '所属事业部',
        field: 'caseLocation',
        minWidth: 150
      },
      {
        title: '所属子公司',
        field: 'caseLocationTwo',
        minWidth: 150
      },
      {
        title: '所属事业处',
        field: 'department',
        minWidth: 150
      },
      {
        title: '所属案场',
        field: 'housesName',
        minWidth: 150
      },
      {
        title: '所属城市',
        field: 'city',
        minWidth: 150
      },
      {
        field: 'receiverCreateTime',
        minWidth: 150,
        title: '配置时间',
        header: {
          filter: dateOpt.range({
            title: '配置时间',
            startKey: 'createStartDate',
            endKey: 'createEndDate',
            disabled: (date) => {
              return date.valueOf() > new Date().getTime()
            },
            check: (val) => {
              if (_this.$tool.dateDiff(val.createStartDate, val.createEndDate).Y >= 2) {
                // 日期最大跨度两年
                _this.$Message.warning('签约日期跨度至多两年。')
              }
              return !(_this.$tool.dateDiff(val.createStartDate, val.createEndDate).Y >= 2)
            }
          })
        }
      },

      {
        title: '运营配置人',
        field: 'receiverCreator',
        minWidth: 150
      },

      {
        title: '操作',
        fixed: 'right',
        width: 220,
        align: 'center',
        slots: {
          default: (params, h) => {
            let btns = []

            btns.push({
              title: '使用记录',
              event: 'useRecord',
              data: params.row
            })
            btns.push({
              title: '通话记录',
              event: 'callRecord',
              data: params.row
            })
            return table.cell.btns(_this, h, btns)
          }
        }
      }
    ]
  }
}

export default Column
